package com.sm.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import com.ygjy.pojo.SmUser;
import com.ygjy.pojo.TwUser;

public class SmSessionUtil {

	public static void invalidateAdmin(HttpServletRequest request, SmUser smuser) {
		HttpSession session = request.getSession();
		session.setAttribute("smuser", smuser);
	}

	public static SmUser getadminuser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		SmUser smUser = null;
		session = request.getSession(true);
		if (session != null && !session.isNew()) {
			smUser = (SmUser) session.getAttribute("smuser");
		}

		return smUser;
	}

	public static void removeAdminUser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		session.removeAttribute("smuser");
	}

	public static void refurbishAdminUser(HttpServletRequest request,
			SmUser smuser) {
		HttpSession session = request.getSession();
		session.removeAttribute("smuser");
		session.setAttribute("smuser", smuser);
	}

	public static void invalidateTwuser(HttpServletRequest request,
			TwUser twuser) {
		HttpSession session = request.getSession();
		session.setAttribute("twuser", twuser);
	}

	public static TwUser gettwuser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		TwUser twuser = null;
		session = request.getSession(true);
		if (session != null && !session.isNew()) {
			twuser = (TwUser) session.getAttribute("twuser");
		}
		return twuser;
	}

	public static void refurbishTwUser(HttpServletRequest request, TwUser twuser) {
		HttpSession session = request.getSession();
		// if ( session!=null && !session.isNew()) {
		// session.removeAttribute("crsuser");
		// }
		if (session != null) {
			session.setAttribute("twuser", twuser);
		}
	}

	public static void removeTwUser(HttpServletRequest request) {
		HttpSession session = request.getSession();
		session.removeAttribute("twuser");
	}

}
